﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    $(function () {
        gridList();
    })

    function gridList() {
        $('#dg').treegrid({
            url: "/SystemManage/Area/GetTreeGridJson",
            toolbar: '#toolbar',
            autoRowHeight: false,
            nowrap: true,
            singleSelect: true,
            idField: 'F_Id',
            treeField: 'F_FullName',
            method: 'get',
            columns: [[
                { field: 'F_Id', hidden: true },
                { field: 'F_FullName', title: '名称', width: 200, align: 'left' },
                {
                    field: 'F_EnabledMark', title: '有效', width: 60, align: 'center',
                    formatter: function (value, row, index) {
                        return value == 1 ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                {
                    field: 'F_CreatorTime', title: '创建时间', width: 130, align: 'right',
                    formatter: function (value, row, index) {
                        if (value) {
                            var time = new Date(value);
                            return time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate();
                        }
                    }
                },
                 { field: 'F_Description', title: '备注', width: 300, align: 'center' },
            ]]
        });

        $("#btn_search").click(function () {
            var queryJson = {
                keyword: $("#txt_keyword").val()
            }
            $('#dg').treegrid('load', queryJson);
        });
    }
    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "新增区域",
            url: "/SystemManage/Area/Form",
            width: "400px",
            height: "360px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_edit() {
        var keyValue = $('#dg').treegrid('getSelected');
        if (keyValue != null) {
            $.modalOpen({
                id: "Form",
                title: "修改区域",
                url: "/SystemManage/Area/Form?keyValue=" + keyValue.F_Id,
                width: "400px",
                height: "360px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        else {
            $.modalMsg("未选中数据", "warning");
        }
    }
    function btn_delete() {
        var keyValue = $('#dg').treegrid('getSelected');
        if (keyValue != null) {
            $.deleteForm({
                url: "/SystemManage/Area/DeleteForm",
                param: { keyValue: keyValue.F_Id },
                success: function () {
                    $('#dg').treegrid('reload');
                }
            })
        }
        else {
            $.modalMsg("未选中数据", "warning");
        }
    }
    function btn_details() {
        var keyValue = $('#dg').treegrid('getSelected');
        if (keyValue != null) {
            $.modalOpen({
                id: "Details",
                title: "查看区域",
                url: "/SystemManage/Area/Details?keyValue=" + keyValue.F_Id,
                width: "400px",
                height: "360px",
                btn: null,
            });
        }
        else {
            $.modalMsg("未选中数据", "warning");
        }
    }
</script>

<div class="easyui-layout" data-options="fit:true">
    <div id="toolbar" style="padding:2px 5px;">
        <div class="dcui-btn-area">
            <a href="#" id="NF-add" authorize="yes" class="dcui-btn dcui-btn-green" iconCls="icon-add" plain="true" onclick="btn_add()"><i class="fa fa-plus"></i>新建区域</a>
            <a href="#" id="NF-delete" authorize="yes" class="dcui-btn dcui-btn-red" iconCls="icon-remove" plain="true" onclick="btn_delete()"><i class="fa fa-trash"></i>删除区域</a>
            <a href="#" id="NF-edit" authorize="yes" class="dcui-btn dcui-btn-blue" iconCls="icon-edit" plain="true" onclick="btn_edit()"><i class="fa fa-pencil"></i>修改区域</a>
            <a href="#" id="NF-details" authorize="yes" class="dcui-btn dcui-btn-purple" iconCls="icon-man" plain="true" onclick="btn_details()"><i class="fa fa-eye"></i>查看区域</a>
        </div>
        <script>$('#toolbar').authorizeButton()</script>
        <div class="dcui-search-area">
            查询条件: <input class="easyui-textbox" style="width:110px" id="txt_keyword" placeholder="请输入要查询的关键字">
            <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="btn_search">查询</a>
        </div>
    </div>

    <table id="dg" class="easyui-treegrid" style="width:100%;min-height:600px;height:100%;"></table>
</div>